<!DOCTYPE html>
<html lang="en">

<head>
  {include file="common/meta" /}
</head>

<body>
  <div class="x-body">

    <!-- 搜索 -->
    <div class="layui-row">
      <form method="get" class="layui-form layui-col-md12 x-so">
        <input class="layui-input" placeholder="开始日" name="start" id="start" value="{$start}" />

        <input class="layui-input" placeholder="截止日" name="end" id="end" value="{$end}" />

        <input type="text" name="keywords" placeholder="" autocomplete="off" value="{$keywords}" class="layui-input">

        <button class="layui-btn">
          <i class="layui-icon">&#xe615;</i>
        </button>
        <button class="layui-btn layui-btn-danger x-right">
          <a href="{:url('admin/post.post/recycle')}"
            style="display: inline-block;width: 100%;height: 100%;color: #fff;">回收站<i
              class="layui-icon">&#xe640;</i></a>
        </button>
      </form>
    </div>

    <xblock>
      <button class="layui-btn layui-btn-danger" onclick="delAll()">
        <i class="layui-icon"></i>批量删除
      </button>

      <span class="x-right" style="line-height:40px">
        共有数据：{$count} 条
      </span>
    </xblock>

    <table class="layui-table">
      <thead>
        <tr>
          <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
            </div>
          </th>
          <th>标题</th>
          <th>所属分类</th>
          <th>悬赏积分</th>
          <th>发布人</th>
          <th>访问次数</th>
          <th>帖子状态</th>
          <th>附加功能</th>
          <th>发布时间</th>
          <th>操作</th>
      </thead>

      <tbody>
        {foreach $postlist as $item}
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
              <i class="layui-icon">&#xe605;</i>
            </div>
          </td>
          <td>{$item.title}</td>
          <td>{$item.cate.name}</td>
          <td>{$item.point}</td>
          <td>{$item.user.nickname}</td>
          <td>{$item.visit_text}</td>
          <td>{$item.accept ? '完结' : '未结'}</td>
          <td>{$item.state_text}</td>
          <td>{$item.createtime}</td>
          <td class="td-manage" style="display:inline-flex;">
            <a target="_blank" title="修改用户信息" class="layui-btn layui-btn-sm layui-btn-normal"
              href="{:url('home/index/info', ['postid' => $item['id']])}" style="width: 80px;">
              查看详情
            </a>

            <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" onclick="del(`{$item['id']}`)"
              href="javascript:;" style="width: 50px;">
              添加回收站
            </a>
          </td>
        </tr>
        {/foreach}
      </tbody>
    </table>

    <div class="page">
      {$pagestr}
    </div>

  </div>
</body>

</html>
<script>
  layui.use('laydate', function () {
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
      elem: '#start' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#end' //指定元素
    });

  });

  // 单个删除
  function del(data) {
    layer.confirm("确认要添加购物车吗？", function (index) {
      layer.close(index);
      deletes(data);
    })
  }

  // 批量删除
  function delAll() {
    var ids = tableCheck.getData();
    layer.confirm("确认批量添加购物车吗？", function (index) {
      var data = ids.join(",");
      deletes(data);
    })
  }

  // 删除请求 
  function deletes(data) {

    // 序列化 将对象转换为参数形式
    var params = {
      ids: data
    }

    params = $.param(params);

    $.ajax({
      type: "POST",
      url: `{:url('admin/post.post/del')}`,
      data: params,
      dataType: "json",
      success: function (data) {
        if (data.result) {
          // 成功
          layer.msg(data.msg, {
            icon: 1,
            time: 2000,
          }, function () {
            // 收藏成功刷新界面
            location.reload();
          })
        } else {
          // 失败
          layer.msg(data.msg);
        }
      }
    })
  }

</script>